﻿				 // input
(function() {

$(window).data('gui').plugins['input'] =
{

  makeHTML : function(param)
  {

    var obj = document.createElement("input");
    obj.setAttribute('data-effect','input');
	param.parent.appendChild(obj);
	
	$(obj).on('keypress', function(event){
		if (event.keyCode == 13) {
			var onenter = this.getAttribute("onenter");
		if (onenter) {
				$(this).off("onenter");
				$(this).on("onenter", new Function(onenter));
			}
			$(this).trigger("onenter");
		}
	});

    obj.setAttribute('type','text');
    return  obj;
  },

  makeXML : function(xml)
  {
	var element = xml.ownerDocument.createElement("input");
	this[0].setAttribute('value',this.value());
	
	return element;
  },
  
  enable : function(flag)
  {
	if (flag !== undefined && flag !== null)
	{
		if (flag == true || flag == false) this[0].disabled = !flag;
		return this;
	} else {
		return (this[0].disabled == false);
	}
  },
  
  readonly : function(flag)
  {
	if (flag !== undefined && flag !== null)
	{	
		if (flag == true || flag == false) this[0].readOnly = flag;
		return this;
	} else {
		return this[0].readOnly;
	}
  },
  
  value : function(val)
  {
	if (val !== undefined && val !== null)
	{
		this[0].value = val;
		return this;
	} else {
		return this[0].value;
	}
  },
   
  autofocus : function(flag)
  {
	if (flag !== undefined && flag !== null)
	{
		if (flag == true || flag == false) this[0].autofocus = flag;
		return this;
	} else {
		return this[0].autofocus;
	}
  }
  }
})();